package com.cet.recon.sftp;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.sftp.session.DefaultSftpSessionFactory;
import org.springframework.integration.sftp.session.SftpRemoteFileTemplate;

@Configuration
public class SftpConfig {
  @Bean
  public DefaultSftpSessionFactory sftpSessionFactory(
      @Value("${sftp.host}") String host,
      @Value("${sftp.port}") int port,
      @Value("${sftp.user}") String user,
      @Value("${sftp.password}") String password) {
    DefaultSftpSessionFactory f = new DefaultSftpSessionFactory(true);
    f.setHost(host); f.setPort(port); f.setUser(user); f.setPassword(password);
    f.setAllowUnknownKeys(true);
    return f;
  }

  @Bean
  public SftpRemoteFileTemplate sftpRemoteFileTemplate(DefaultSftpSessionFactory factory) {
    return new SftpRemoteFileTemplate(factory);
  }
}
